import { Route, Switch, NavLink, Link ,Redirect} from 'react-router-dom'
import {Suspense} from "react"
let RouterView = (props) => {
 
    let { RouterList } = props
    let routerList = RouterList.filter((item) => {
        return !item.to
    })
    let redirect = RouterList.filter((item) => {
        return item.to
    })[0]
    // console.log(routerList,redirect);
    return (
        <Suspense fallback={<div>...laoding</div>}>
            <Switch>
                {
                    routerList && routerList.length ? routerList.map((item,index)=>{
                        return <Route path={item.path} key={index} render={(routerProps)=>{
                            // routerProps 就是路由信息参数
                            window.routerprops= routerProps 
                            return <item.component {...routerProps}></item.component>
                        }}></Route>
                    }):""
                }
                {
                    redirect ? <Redirect from={redirect.from} to={redirect.to}></Redirect>:"暂无重定向"
                }
            </Switch>
        </Suspense>
    )
}
export default RouterView